//setInterval( "loadPrevious()", 60*1000);

var lastId = 43;
var currId = 43;
var feedURL = "http://media.eurotrip.com.ar/gadget.txt"; 
var baseURL = "http://media.eurotrip.com.ar/";

function loadLastId() {
	loadAll();
}

function loadAll() {
	var http = new XMLHttpRequest();
	http.onreadystatechange = function() {
		if (http.readyState == 4) { // completed?
			currId = lastId = http.responseText;
			loadImage(lastId);
		}
	};
	http.open("GET", feedURL, true);
	http.send();
}

function loadImage(id) {
	var http = new XMLHttpRequest(); 
	var url = baseURL+id+".jpg"; 
	http.onreadystatechange = function onData() { 
		if(http.readyState == 4) { 
			illustrationImage.src = http.responseStream; 
			http = null;
		}
	};
	http.open("GET", url, true); 
	http.send(); 
}

function loadPrevious() {
	currId--;
	if(currId == 0) currId = lastId;
	loadImage(currId);
}

function loadNext() {
	currId++;
	if(currId > lastId) currId = 1;
	loadImage(currId);
}
